﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DEEBCG.ExternalLib.CompanyAPI.Model
{
    /// <summary>
    /// 接入账号信息
    /// </summary>
    public class AppInfo
    {
        /// <summary>
        /// 初始化（自动生成NoiseStr和Timestamp）
        /// </summary>
        /// <param name="appID">AppID</param>
        /// <param name="secret">密钥</param>
        /// <param name="appName">App名称</param>
        public AppInfo(string appID,string secret,string appName) {
            AppID = appID;
            Secret = secret;
            AppName = appName;
            NoiseStr = Guid.NewGuid().ToString();
            Timestamp = Utils.ConvertDateTime(DateTime.Now);
        }

        /// <summary>
        /// AppID
        /// </summary>
        public string AppID { set;get; }
        /// <summary>
        /// 密钥
        /// </summary>
        public string Secret { set;get; }
        /// <summary>
        /// App名称
        /// </summary>
        public string AppName { set;get; }
        /// <summary>
        /// 随机字串
        /// </summary>
        public string NoiseStr { set;get; }
        /// <summary>
        /// 时间戳(毫秒)
        /// </summary>
        public long Timestamp { set; get; }

        /// <summary>
        /// 获取Password
        /// </summary>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public string GetPassword()
        {
            if (string.IsNullOrEmpty(AppID) || string.IsNullOrEmpty(Secret) || string.IsNullOrEmpty(AppName) ||
                string.IsNullOrEmpty(NoiseStr) || Timestamp == 0)
            {
                throw new ArgumentException("请设置APP相关参数值生再生成Password。");
            }

            return Utils.Sha1($"{AppID}_{NoiseStr}_{Secret}_{AppName}_{Timestamp}");
        }
    }
}
